package cn.sxt.userscenter.common.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.RequestMapping;

import cn.sxt.userscenter.common.util.EncryptUtil;
import cn.sxt.userscenter.common.util.VerifyCodeUtils;
/**
 * controller的父类
 * @author PC-CZ
 *
 */
public class BaseController{
	/**
	 * 用于加密的工具类属性
	 */
	@Resource
	protected EncryptUtil encryptUtil;

	/**
	 * 提示信息
	 * 用于存放返回到页面的提示信息
	 */
	protected String info;
	
	public String getInfo() {
		return info;
	}
	
	public void setInfo(String info) {
		this.info = info;
	}
	
	/**
	 * 生成验证码
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/randImg")
	public String randImg(HttpServletRequest request,HttpServletResponse response) throws IOException{
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/jpeg");
		
		//生成随机字符串  设定生成验证码的位数
		String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
		//存入会话
		HttpSession session = request.getSession();
		session.setAttribute("rand", verifyCode.toLowerCase());
		
		//生成图片
		int w = 200, h = 80;
		VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
		
		return null;//不跳转页面
	}
	
	
	
	
}
